import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(GetMaterialApp(
    home: CounterPage(),
  ));
}

class CounterPage extends StatefulWidget {
  const CounterPage({super.key});

  @override
  State<CounterPage> createState() => _CounterPageState();
}

class _CounterPageState extends State<CounterPage> {
  RxInt _counter = 0.obs;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('计数器'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _counter++;
        },
        child: const Icon(Icons.add),
      ),
      body: Center(
        child: Column(
          children: [
            Obx(() => Text('${_counter.value}')),
          ],
        ),
      ),
    );
  }
}

/// 声明响应式变量的流程
///  1.GetMaterialApp
///  2.Rx...类型，然后初始化后加入.obs,example:RxInt _counter = 0.obs;
///  3.Obx(() => Text('${_counter.value}'))动监煎态jianting
